Skip to content

Latest commit

 

History

History
38 lines (31 loc) · 922 Bytes

File metadata and controls

38 lines (31 loc) · 922 Bytes

1016. Binary String With Substrings Representing 1 To N

Given a binary string s and a positive integer n, return trueif the binary representation of all the integers in the range[1, n]are substrings ofs, orfalseotherwise.

A substring is a contiguous sequence of characters within a string.

Example 1:

Input: s = "0110", n = 3 Output: true 

Example 2:

Input: s = "0110", n = 4 Output: false 

Constraints:

  • 1 <= s.length <= 1000
  • s[i] is either '0' or '1'.
  • 1 <= n <= 109

Solutions (Rust)

1. Solution

implSolution{pubfnquery_string(s:String,n:i32) -> bool{for x in1..=n {if !s.contains(&format!("{:b}", x)){returnfalse;}}true}}
close